/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dnbW.uiW.queryW.modelW;

import dnbW.dbW.DatabaseInfo;
import java.util.HashMap;

/**
 * This is the manager that manages the join connection between data sources of an database
 * @author Truong Ba Quan
 */
public class JoinManager {
    private DatabaseInfo database;

    public DatabaseInfo getDatabase() {
        return database;
    }

    /**
     * A map from the two data source names to the joins
     * The key is the concatenation of two data sources name (separated by ----) (a simple way for 2-dimensional map)
     * The value is the join
     */
    private HashMap<String, JoinNodeObject> joinMaps = new HashMap<String, JoinNodeObject>();

    public JoinNodeObject getJoin(String dataSourceName1, String dataSourceName2) {
        JoinNodeObject join = this.joinMaps.get(dataSourceName1 + "----" + dataSourceName2);
        if (join != null) return join;
        else {
            join = this.joinMaps.get(dataSourceName2 + "----" + dataSourceName1);
            return join;
        }
    }

    public void putJoin(String dataSourceName1, String dataSourceName2, JoinNodeObject join) {
        this.joinMaps.put(dataSourceName1 + "----" + dataSourceName2, join);
    }
}
